package com.substation.ui.activity;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;

import com.jessewu.library.SuperAdapter;
import com.jessewu.library.builder.FooterBuilder;
import com.jessewu.library.paging.LoadDataListener;
import com.jessewu.library.paging.LoadDataStatus;
import com.jessewu.library.widget.SimpleFooterBuilder;
import com.substation.R;

import butterknife.BindView;

/**
 * Created by admin on 2018/5/15.
 */

public abstract class BaseListActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener {

    @BindView(R.id.list)
    RecyclerView list;
    @BindView(R.id.refresh)
    SwipeRefreshLayout refresh;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    LoadDataStatus loadDataStatus;//加载更多。。。
    int page=1;
    int limit=15;

    @Override
    protected int getLayoutId() {
        return getMyListLayoutId() == 0 ? R.layout.activity_base_list : getMyListLayoutId();
    }

    @Override
    protected void initView() {
        refresh.setColorSchemeColors(new int[]{R.color.colorAccent, R.color.colorPrimary, R.color.colorPrimaryDark});
        refresh.setOnRefreshListener(this);
        list.setLayoutManager(getLayoutManager() == null ? new LinearLayoutManager(getApplicationContext()) : getLayoutManager());
        list.setAdapter(getAdapter());
    }

    protected  int getMyListLayoutId(){
        return 0;
    }


    @Override
    public void onRefresh() {

    }

    public  RecyclerView.LayoutManager getLayoutManager(){
        return null;
    }

    public abstract SuperAdapter getAdapter();

    public FooterBuilder getLoadMoreFooter() {
        return new SimpleFooterBuilder("这是个底部", "正在加载数据中", "加载数据失败", "已经到底啦");
    }

    public LoadDataListener getLoadMoreListener(){
        return new LoadDataListener() {
            @Override
            public void onLoadingData(int loadPage, LoadDataStatus loadDataStatus) {
                loadMore(loadPage, loadDataStatus);
            }
        };
    }

    public void loadMore(int loadPage, LoadDataStatus loadDataStatus){

    }

}
